luci-base: package update based cache-busting string
authorOleg S <[email protected]>
Mon, 14 Apr 2025 13:08:45 +0000 (16:08 +0300)
committerPaul Donald <[email protected]>
Mon, 14 Apr 2025 13:16:54 +0000 (15:16 +0200)
Problem:
After updating the JS-part of any package, the user is forced to clear
the browser cache.

Fix:
Each time a package is removed or installed, the contents of the
"/lib/apk/db/installed" file are changed.
This fix add the modification time of the "/lib/apk/db/installed" file
to the version of the main LuCI package (for each js-file).

Signed-off-by: Oleg S <[email protected]>
modules/luci-base/ucode/runtime.uc
modules/luci-base/ucode/template/header.ut

index f14bf74480c8d6c6eab1fc8f88b4f7d0b12fbb24..e5f11690dfbdb2fe2a7fed6531d66cc7e25a331f 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright 2022 Jo-Philipp Wich <[email protected]>
 // Licensed to the public under the Apache License 2.0.
 
-import { access, basename } from 'fs';
+import { access, basename, stat } from 'fs';
 import { cursor } from 'uci';
 
 const template_directory = '/usr/share/ucode/luci/template';
@@ -179,6 +179,7 @@ export default function(env) {
        self.env.media = media;
        self.env.theme = basename(media);
        self.env.resource = uci.get('luci', 'main', 'resourcebase');
+       self.env.pkgs_update_time = stat('/lib/apk/db/installed')?.mtime ?? stat('/usr/lib/opkg/status')?.mtime ?? 0;
        self.env.include = (...args) => self.render_any(...args);
 
        return self;
index 7a8462d61d7a107af46c08c86e27f4caefaf3ee6..f23e5e45c88211d3d500193407f9277f1912c784 100644 (file)
@@ -7,7 +7,7 @@
        include(`themes/${theme}/header`);
 -%}
 
-<script src="{{ resource }}/luci.js"></script>
+<script src="{{ resource }}/luci.js?v={# PKG_VERSION #}-{{ pkgs_update_time }}"></script>
 <script>
        L = new LuCI({{ replace(`${ {
                media          : media,